﻿using System.Data.Common;
using NUnit.Framework;
using EntlibData = Microsoft.Practices.EnterpriseLibrary.Data;
namespace jcs.Core.Data.Tests
{
    /// <summary>
    /// Summary description for UnitTest1
    /// </summary>
    [TestFixture]
    public class DataProviderTests
    {
        [Test]
        public void GetCommandTests()
        {
            var Db = EntlibData.DatabaseFactory.CreateDatabase();
            DbCommand Cmd = null;
            try
            {
                const string selectFromSysDatabases = "select * from sys.databases";
                Cmd = DataProvider.GetCommand(string.Empty, selectFromSysDatabases, DataProvider.EntlibDataCommandType.SqlString, false);
                Assert.AreNotEqual(null, Cmd);
                Assert.AreEqual(selectFromSysDatabases, Cmd.CommandText);
                Assert.AreEqual(300, Cmd.CommandTimeout);
            }
            finally
            {
                if (Cmd != null) {DataProvider.SwatFlyWithBuick(ref Cmd);}
            }
        }

        [Test]
        public void GetDataReaderTests()
        {

            var Dr = DataProvider.GetDataReader("sp_who", "");
            Assert.AreNotEqual(null, Dr);

            var I = 0;
            while (Dr.Read())
            {
                I += 1;
            }

            Assert.IsTrue(I > 0);

            DataProvider.SwatFlyWithBuick(ref Dr);
            Assert.AreEqual(null, Dr);

        }

        [Test]
        public void GetDataTableTests()
        {

            var Dt = DataProvider.GetDataTable("sp_who", "");
            Assert.AreNotEqual(null, Dt);
            Assert.AreNotEqual(0, Dt.Rows.Count);

        }


    }
}
